package com.binvshe.binvshe.mine.view;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.binvshe.binvshe.R;

import java.util.ArrayList;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/7/15
 */
public class ChooseSexDialog extends DialogFragment implements View.OnClickListener {

    private SexClickable mOnClickable;
    private WheelView mWheelViewSex;
    private int mSex = 2;

    @Override
    public void onStart() {
        super.onStart();
        getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        Window window = getDialog().getWindow();
        window.setWindowAnimations(R.style.AnimBottom); //设置窗口弹出动画
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.frag_alert_chose_sex, container);
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        View vwBlank = view.findViewById(R.id.mVwBlank);
        vwBlank.setOnClickListener(this);
        TextView btnCannel =  (TextView) view.findViewById(R.id.btn_cancel);
        btnCannel.setOnClickListener(this);
        TextView btnEnter = (TextView) view.findViewById(R.id.btn_enter);
        btnEnter.setOnClickListener(this);
        mWheelViewSex = (WheelView) view.findViewById(R.id.wvSex);
        mWheelViewSex.setData(getData());
        return view;
    }

    private ArrayList<String> getData() {
        ArrayList<String> data = new ArrayList<>();
        data.add("男");
        data.add("女");
        return data;
    }

    private String getSelectedText(){
        return mWheelViewSex.getSelectedText();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.mVwBlank:
                dismiss();
                break;
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_enter:
                if (getSelectedText().equals("女")||getSelectedText() == "女"){
                    mSex = 0;
                }else if (getSelectedText().equals("男")||getSelectedText() == "男"){
                    mSex = 1;
                }
                mOnClickable.btnEnter(mSex);
                dismiss();
                break;
        }
    }

    public void setmOnClickable(SexClickable mOnClickable) {
        this.mOnClickable = mOnClickable;
    }

    public interface SexClickable {
        void btnEnter(int sex);
    }
}
